package com.observe.pattern.service;

import com.observe.pattern.event.EventManager;
import com.observe.pattern.event.MQEventListener;
import com.observe.pattern.event.MessageEventListener;

/**
 * @author cc
 * @classname LotteryService
 * @description 业务抽象类接⼝
 * @date 2022/3/29 13:33
 */
public abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService() {
        eventManager = new EventManager(EventManager.EventType.Message, EventManager.EventType.MQ);
        eventManager.subscribe(EventManager.EventType.Message, new MessageEventListener());
        eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
    }

    public String draw(String uid) {
        String result = doDraw(uid);
        //需要什么通知就给调⽤什么⽅法    给用户发通知消息    按需添加
        eventManager.notify(EventManager.EventType.MQ, uid);
        eventManager.notify(EventManager.EventType.Message, uid);
        return result;
    }

    //保证将来外部的调⽤⽅不会调⽤到此⽅法，只有调⽤到 draw(String uid) ，才能让我们完成事件通知。
    protected abstract String doDraw(String uid);
}
